<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="160px"
    >
      <el-form-item label="计划开工时间：">
        <el-date-picker
          v-model="daterangePlannedStartTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开工时间"
          end-placeholder="完工时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="订单类型：" prop="orderType">
        <el-select
          v-model="queryParams.orderType"
          placeholder="请选择订单类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.project_order_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="项目名称：" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="合同编号：" prop="contractNo">
        <el-input
          v-model="queryParams.contractNo"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="项目状态：" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择项目状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.project_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['Project:ProjectInfo:add']"
          >新增</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['Project:ProjectInfo:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['Project:ProjectInfo:remove']"
          >删除</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['Project:ProjectInfo:export']"
          >项目列表导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-download"
          size="mini"
          @click="handleExportCome"
          v-hasPermi="['Project:ProjectInfo:export']"
          >项目构件导出</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="ProjectInfoList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="项目编号" align="center" prop="projectNo" />
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目简介" align="center" prop="projectSname" />
      <el-table-column label="项目地址" align="center" prop="projectAddr" />
      <el-table-column label="对方单位" align="center" prop="oppositeCompany" />
      <el-table-column label="订单类型" align="center" prop="orderType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.project_order_type"
            :value="scope.row.orderType"
          />
        </template>
      </el-table-column>
      <el-table-column label="合同编号" align="center" prop="contractNo" />
      <el-table-column label="结构量" align="center" prop="structCount" />
      <el-table-column label="经办人" align="center" prop="operator" />
      <el-table-column label="已产构件数" align="center" prop="proCompCount" />
      <el-table-column
        label="已发货构件数"
        align="center"
        prop="issCompCount"
      />
      <el-table-column label="未排构件数" align="center" prop="notCompCount" />
      <el-table-column label="项目状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.project_status"
            :value="scope.row.status"
          />
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="comment" />
      <el-table-column
        label="签订日期"
        align="center"
        prop="signingTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.signingTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="计划开工时间"
        align="center"
        prop="plannedStartTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.plannedStartTime, "{y}-{m}-{d}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="交付时间"
        align="center"
        prop="dueTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dueTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['Project:ProjectInfo:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['Project:ProjectInfo:remove']"
            >删除</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="check(scope.row)"
            v-hasPermi="['Project:ProjectInfo:edit']"
            >查看</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目信息对话框 -->
    <!-- <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="项目简介" prop="projectSname">
          <el-input v-model="form.projectSname" placeholder="请输入项目简介" />
        </el-form-item>
        <el-form-item label="项目地址" prop="projectAddr">
          <el-input v-model="form.projectAddr" placeholder="请输入项目地址" />
        </el-form-item>
        <el-form-item label="对方单位" prop="oppositeCompany">
          <el-input
            v-model="form.oppositeCompany"
            placeholder="请输入对方单位"
          />
        </el-form-item>
        <el-form-item label="订单类型" prop="orderType">
          <el-select v-model="form.orderType" placeholder="请选择订单类型">
            <el-option
              v-for="dict in dict.type.project_order_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="合同编号" prop="contractNo">
          <el-input v-model="form.contractNo" placeholder="请输入合同编号" />
        </el-form-item>
        <el-form-item label="结构量" prop="structCount">
          <el-input v-model="form.structCount" placeholder="请输入结构量" />
        </el-form-item>
        <el-form-item label="经办人" prop="operator">
          <el-input v-model="form.operator" placeholder="请输入经办人" />
        </el-form-item>
        <el-form-item label="已产构件数" prop="proCompCount">
          <el-input
            v-model="form.proCompCount"
            placeholder="请输入已产构件数"
          />
        </el-form-item>
        <el-form-item label="已发货构件数" prop="issCompCount">
          <el-input
            v-model="form.issCompCount"
            placeholder="请输入已发货构件数"
          />
        </el-form-item>
        <el-form-item label="未排构件数" prop="notCompCount">
          <el-input
            v-model="form.notCompCount"
            placeholder="请输入未排构件数"
          />
        </el-form-item>
        <el-form-item label="项目状态">
          <el-radio-group v-model="form.status">
            <el-radio
              v-for="dict in dict.type.project_status"
              :key="dict.value"
              :label="dict.value"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="comment">
          <el-input
            v-model="form.comment"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="签订日期" prop="signingTime">
          <el-date-picker
            clearable
            v-model="form.signingTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择签订日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="计划开工时间" prop="plannedStartTime">
          <el-date-picker
            clearable
            v-model="form.plannedStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择计划开工时间"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="交付时间" prop="dueTime">
          <el-date-picker
            clearable
            v-model="form.dueTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择交付时间"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import {
  exportMember,
  listProjectInfo,
  getProjectInfo,
  delProjectInfo,
  addProjectInfo,
  updateProjectInfo,
} from "@/api/project/ProjectInfo";

export default {
  name: "ProjectInfo",
  dicts: ["project_status", "project_order_type"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目信息表格数据
      ProjectInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 交付时间时间范围
      daterangePlannedStartTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectNo: null,
        projectName: null,
        projectSname: null,
        projectAddr: null,
        oppositeCompany: null,
        orderType: null,
        contractNo: null,
        structCount: null,
        operator: null,
        proCompCount: null,
        issCompCount: null,
        notCompCount: null,
        status: null,
        comment: null,
        signingTime: null,
        plannedStartTime: null,
        dueTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      // rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询项目信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (
        null != this.daterangePlannedStartTime &&
        "" != this.daterangePlannedStartTime
      ) {
        this.queryParams.params["beginPlannedStartTime"] =
          this.daterangePlannedStartTime[0];
        this.queryParams.params["endPlannedStartTime"] =
          this.daterangePlannedStartTime[1];
      }
      listProjectInfo(this.queryParams).then((response) => {
        this.ProjectInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        projectNo: null,
        projectName: null,
        projectSname: null,
        projectAddr: null,
        oppositeCompany: null,
        orderType: null,
        contractNo: null,
        structCount: null,
        operator: null,
        proCompCount: null,
        issCompCount: null,
        notCompCount: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        status: "0",
        comment: null,
        signingTime: null,
        plannedStartTime: null,
        dueTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangePlannedStartTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd(item) {
      this.reset();
      // this.open = true;
      // this.title = "添加项目信息";
      this.$router.push({
        path: "/ProjectInfo/projectNew",
        query: { id: item.id },
      });
    },
    /** 修改按钮操作 */
    handleUpdate(item) {
      console.log("item", item);
      this.reset();
      // const id = row.id || this.ids;
      // updateProjectInfo(id).then((response) => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "编辑项目";
      // });

      this.$router.push({
        path: "/ProjectInfo/projectEidt",
        query: {
          id: item.id,
          projectNo: item.projectNo,
        },
      });
    },
    // 查看按钮
    check(item) {
      console.log("item", item);
      this.reset();
      // const id = row.id || this.ids;
      // updateProjectInfo(id).then((response) => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "编辑项目";
      // });

      this.$router.push({
        path: "/ProjectInfo/projectCheck",
        query: {
          id: item.id,
          projectNo: item.projectNo,
        },
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateProjectInfo(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProjectInfo(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除项目信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delProjectInfo(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "Project/ProjectInfo/export",
        {
          ...this.queryParams,
        },
        `ProjectInfo_${new Date().getTime()}.xlsx`
      );
    },
    handleExportCome(){
      this.download(
        "Project/ProjectInfo/exportMember",
        {
          ...this.queryParams,
        },
        `ProjectMember_${new Date().getTime()}.xlsx`
      );
    }

  },
};
</script>
